﻿using System;
using System.Text;
using System.Windows.Forms;



namespace Voize
{
    internal class CScrollingDisplay
    {



        internal CScrollingDisplay(ref Label label)
        {
            m_LabelOrigLeftPos = label.Left;
            m_Label = label;
            m_ScrollDelegate = new ScrollDelegate(ScrollText);
            m_Timer = new Timer();
            m_Timer.Interval = m_TimerInterval;
            m_Timer.Tick += new EventHandler(m_Timer_Tick);
        }

        void m_Timer_Tick(object sender, EventArgs e)
        {
            m_ScrollDelegate.Invoke();
        }



        private delegate void ScrollDelegate();
        private Label m_Label;
        private string m_DisplayText;
        private ScrollDelegate m_ScrollDelegate;
        private Timer m_Timer;
        private const int m_TimerInterval = 60;
        private int m_LabelOrigLeftPos;
		private bool m_IsScrolling;



        internal string SetDisplayText
        {
            get { return m_DisplayText; }
            set 
            {
                m_Label.Left = m_LabelOrigLeftPos;
                m_DisplayText = value;
                m_Label.Text = m_DisplayText;
            }
        }



		internal bool IsScrolling
		{
			get { return m_IsScrolling; }
			set { m_IsScrolling = value; }
		}



        internal void StartScrolling()
        {
            m_Timer.Start();
			m_IsScrolling = true;
        }



        internal void StopScrolling()
        {
            m_Timer.Stop();
			m_IsScrolling = false;
			m_Label.Left = m_LabelOrigLeftPos;
        }



        private void ScrollText()
        {
            this.m_Label.Left -= 2;
            if (m_Label.Left < -300)
                m_Label.Left = m_LabelOrigLeftPos + 305;
            
        }



    }
}
